<?php
/**
 * Prado Portal.
 *
 * @author Steen Rabol <steen.rabol@gmail.com>
 * @link http://www.pradoportal.dk/
 * @copyright Copyright &copy; 2006,2007,2008 Steen Rabol
 * @license http://www.pradoportal.dk
 * @version $Id: ViewUser.php 367 2010-02-06 20:04:08Z steen.rabol@gmail.com $
 *
 */

Prado::using('Application.Common.Data.PortalUserRecord');

class ViewUser extends PortalSystemPage
{
	private $_userRecord=null;

	public function onInit($param)
	{
		if(!isset($this->Request['id']) || $this->Request['id'] == 0 || $this->Request['id'] === '0')
		{
			//$this->reportError(1,Prado::localize("Invalid or missing profile id"));
			$this->Request['id'] = $this->User->Id;
		}

		parent::onInit($param);

		if(($id = TPropertyValue::ensureInteger($this->Request['id'])) !== null)
		{
			if($this->User->RoleId != $this->Application->Parameters['AdminRole'] && $this->User->Id !== $id)
			{
				throw new PortalException(500,Prado::localize("You are not allowed to view this profile"));
			}
		}

		if(($id=$this->Request['id'])!==null)
		{
			$id	= TPropertyValue::ensureInteger($id);
		}
		else if($this->Request['id'] == 0 || $this->Request['id'] === '0')
		{
			throw new PortalException(500,'profile_id_invalid',$id);
		}
		else
		{
			$id	= $this->User->Id;
		}

		$this->_userRecord = PortalUserRecord::finder()->findByid($id);
	}

	public function onLoad($param)
	{
		parent::onLoad($param);
		$this->Title = $this->Application->Parameters['SiteTitle'] . " - " . Prado::localize("View profile");
	}

	public function getProfile()
	{
		return $this->_userRecord;
	}
}
?>